import 'package:flutter/cupertino.dart';
import 'package:s_k_todo/data/base_data.dart';

import '../data/dio_static.dart';

import '../model/task_model.dart';

class TaskListProvider extends ChangeNotifier {
  final List<TaskInfo> _taskList = [];
  int? curTaskId;

  late final TaskApi _taskApi = TaskApi(DioStatic.getInstance().dio);

  Future<void> getTaskList() async {
    BaseData<List<TaskInfo>> result = await _taskApi.getTaskList();
    if (result.code == 0 && result.data != null) {
      _taskList.clear();
      _taskList.addAll(result.data!);
    }
    notifyListeners();
  }

  List<TaskInfo> get taskList => _taskList;

  void addNewTask(TaskInfo data) {
    _taskList.add(data);
    notifyListeners();
  }

  void selectTask(int index) {
    curTaskId = _taskList[index].id;
    notifyListeners();
  }
}
